<template>
    <el-dialog :visible.sync="visible" width="700px" :close-on-click-modal="false" :show-close="true" :title="null"
        custom-class="knowledge-dialog tech-dialog-body" @close="handleClose">
        <template #title></template> <div class="dialog-content tech-content">
            
            <div class="dialog-header tech-header">
                <span class="dialog-title neon-title-modal">
                    📖 知识库信息编辑 <span class="sub-title-log">// EDIT KNOWLEDGE BASE</span>
                </span>
                </div>
            
            <div style="display: flex;">
                <div class="dialog-icon tech-icon-area">
                    <img src="@/assets/images/knowledge/knowledge-icon.png" alt="icon" class="tech-icon-glow-border" />
                </div>
                
                <div class="dialog-form tech-form-area">
                    <el-form ref="form" :model="dataInfo" :rules="rules" label-position="top" class="form-body">
                        
                        <el-form-item label="知识库名称" prop="name" class="tech-form-item">
                            <el-input v-model="dataInfo.name" placeholder="输入知识库名称"
                                prefix-icon="el-icon-collection-tag" class="tech-input" />
                        </el-form-item>

                        <el-form-item label="知识库描述" prop="description" class="tech-form-item">
                            <el-input type="textarea" v-model="dataInfo.description" :rows="4" maxlength="500"
                                show-word-limit placeholder="描述这个知识库的用途和内容..." class="tech-textarea" />
                        </el-form-item>

                    </el-form>

                    <div class="dialog-footer">
                        <el-button @click="handleClose" class="tech-button secondary-btn">取消 (CANCEL)</el-button>
                        <el-button type="primary" @click="handleSubmit"
                            class="tech-button primary-btn">确认 (SAVE)</el-button>
                    </div>
                </div>
            </div>

        </div>
    </el-dialog>
</template>

<script>
// JavaScript 逻辑保持不变
export default {
    name: 'KnowledgeEditModal', // 注意：组件名是 KnowledgeEditModal，但原代码注释是 KnowledgeCreateModal
    props: {
        visible: {
            type: Boolean,
            required: true
        },
        dataInfo: {
            type: Object,
            default: () => ({})
        }
    },
    data() {
        return {
            form: {
                name: '',
                description: ''
            },
            rules: {
                name: [{ required: true, message: '请输入知识库名称', trigger: 'blur' }],
                description: [{ max: 500, message: '最多输入500字', trigger: 'blur' }]
            },
            activeNames: []
        }
    },
    methods: {
        handleSubmit() {
            this.$refs.form.validate(valid => {
                if (valid) {
                    // 提交 dataInfo 的数据
                    this.$emit('submit', { ...this.dataInfo })
                }
            })
        },
        handleClose() {
            this.$emit('update:visible', false)
            // 由于 model 是 props 的 dataInfo，这里不需要 resetFields
            // 如果需要重置，建议在父组件中传递 dataInfo 的副本
            // this.$refs.form.resetFields() 
        }
    }
}
</script>

<style scoped lang="less">
/* ================= 赛博朋克主题变量 (重复以便独立调试) ================= */
@bg-dark: #0f1219;
@bg-panel: rgba(26, 31, 44, 0.9);
@primary-color: #00f2ff; /* Cyber Cyan */
@accent-color: #7d2ae8;  /* Neon Purple */
@text-main: #e2e8f0; // 浅色主文本
@text-sub: #94a3b8;  // 辅助文本
@border-color: rgba(0, 242, 255, 0.3); // 霓虹边框色

/* ================= 弹窗主体样式覆盖 ================= */
.knowledge-dialog {
    padding: 0;

    // 弹窗边框/背景
    &.tech-dialog-body {
        background: @bg-panel !important;
        border: 2px solid @border-color !important;
        box-shadow: 0 0 25px rgba(0, 242, 255, 0.4) !important;
        border-radius: 8px !important;
        overflow: hidden;
    }

    // 移除默认头部，我们自定义
    ::v-deep .el-dialog__header {
        display: none;
    }

    // 覆盖 Element UI 关闭按钮
    ::v-deep .el-dialog__headerbtn .el-dialog__close {
        color: @text-sub;
        font-size: 18px;
        transition: color 0.3s;
        &:hover {
            color: #ff6666;
            text-shadow: 0 0 10px #ff6666;
        }
    }
    
    // 弹窗内容区
    ::v-deep .el-dialog__body {
        padding: 0px;
        margin: 0px;
    }
}

.dialog-content.tech-content {
    background: transparent;
    color: @text-main;
}

/* ================= 头部样式 ================= */
.dialog-header.tech-header {
    height: auto;
    background-color: transparent;
    display: flex;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid @border-color;
}

.neon-title-modal {
    color: @primary-color;
    text-shadow: 0 0 12px rgba(0, 242, 255, 0.7);
    font-size: 24px;
    font-weight: 700;
    
    .sub-title-log {
        font-size: 14px;
        color: @text-sub;
        margin-left: 10px;
        font-weight: normal;
    }
}


/* ================= 左侧图标区域 ================= */
.dialog-icon.tech-icon-area {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30%;
    // 添加一个深色的背景区分
    background: rgba(0, 0, 0, 0.2); 
    padding: 24px 0;
}

.tech-icon-glow-border {
    width: 100px;
    height: 100px;
    border-radius: 16px;
    // 图片周围添加光晕效果
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.2), 0 0 30px @primary-color; 
    border: 2px solid @primary-color;
    transition: all 0.3s;
}

/* ================= 右侧表单区域 ================= */
.dialog-form.tech-form-area {
    width: 70%;
    padding: 24px;
}

.form-body ::v-deep .el-form-item {
    margin-bottom: 20px;

    // Label 样式
    .el-form-item__label {
        color: @text-main;
        font-weight: 600;
        font-size: 14px;
    }
}

/* ================= 表单输入框覆盖 ================= */
::v-deep .tech-input, ::v-deep .tech-textarea {
    
    // 输入框背景和文字颜色
    .el-input__inner, .el-textarea__inner {
        background-color: rgba(0, 0, 0, 0.4) !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        color: @text-main !important;
        border-radius: 4px;
        transition: all 0.3s;
    }

    // 聚焦效果
    .el-input__inner:focus, .el-textarea__inner:focus {
        border-color: @primary-color !important;
        box-shadow: 0 0 10px rgba(0, 242, 255, 0.5);
    }
    
    // Placeholder 颜色
    .el-input__inner::placeholder, .el-textarea__inner::placeholder {
        color: @text-sub;
    }
    
    // Icon 颜色
    .el-input__prefix .el-input__icon {
        color: @accent-color;
    }
    
    // Textarea 字数限制提示
    .el-input__count {
        background: transparent !important;
        color: @text-sub;
    }
}

/* ================= 底部按钮区域 ================= */
.dialog-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 15px;
}

.tech-button {
    border-radius: 4px;
    padding: 10px 18px;
    font-weight: 600;
    transition: all 0.3s;

    // 取消按钮 (Secondary)
    &.secondary-btn {
        background: rgba(255, 255, 255, 0.1) !important;
        border: 1px solid @text-sub !important;
        color: @text-main !important;
        &:hover {
            border-color: @primary-color !important;
            color: @primary-color !important;
        }
    }

    // 确认按钮 (Primary)
    &.primary-btn {
        background: linear-gradient(90deg, @primary-color, @accent-color) !important;
        border: none !important;
        color: #fff !important;
        box-shadow: 0 0 10px rgba(0, 242, 255, 0.3);
        margin-left: 10px;
        
        &:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 15px rgba(0, 242, 255, 0.6);
        }
    }
}

</style>